//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "CPISwap.h"
using namespace Cephei::QL::Instruments;
#include <gen/QL/CashFlow.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Times/Schedule.h>
#include <gen/QL/Indexes/IborIndex.h>
#include <gen/QL/Times/Period.h>
#include <gen/QL/Indexes/ZeroInflationIndex.h>
#include <gen/QL/PricingEngine.h>
#include <gen/QL/Instruments/Swap.h>
using namespace Cephei::QL;
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Indexes;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Instruments::CCPISwap::CCPISwap (QL::Instruments::CPISwap::TypeEnum type, Double nominal, Boolean subtractInflationNominal, Double spread, Cephei::QL::Times::IDayCounter^ floatDayCount, Cephei::QL::Times::ISchedule^ floatSchedule, QL::Times::BusinessDayConventionEnum floatRoll, UInt32 fixingDays, Cephei::QL::Indexes::IIborIndex^ floatIndex, Double fixedRate, Double baseCPI, Cephei::QL::Times::IDayCounter^ fixedDayCount, Cephei::QL::Times::ISchedule^ fixedSchedule, QL::Times::BusinessDayConventionEnum fixedRoll, Cephei::QL::Times::IPeriod^ observationLag, Cephei::QL::Indexes::IZeroInflationIndex^ fixedIndex, Microsoft::FSharp::Core::FSharpOption<QL::Cashflows::CPI::InterpolationTypeEnum>^ observationInterpolation, Microsoft::FSharp::Core::FSharpOption<Double>^ inflationNominal, Cephei::QL::IPricingEngine^ QL_Pricer) : CSwap(CCPISwap::typeid)
{
    CDayCounter^ _CfloatDayCount;
    CSchedule^ _CfloatSchedule;
    CIborIndex^ _CfloatIndex;
    CDayCounter^ _CfixedDayCount;
    CSchedule^ _CfixedSchedule;
    CPeriod^ _CobservationLag;
    CZeroInflationIndex^ _CfixedIndex;
    try
    {
#ifdef HANDLE
        _phCPISwap = NULL;
#endif
        QuantLib::CPISwap::Type _type = (QuantLib::CPISwap::Type)type ;
        QuantLib::Real _nominal = (QuantLib::Real)ValueHelper::Convert (nominal); //d
        bool _subtractInflationNominal = (bool)ValueHelper::Convert (subtractInflationNominal); //d
        QuantLib::Spread _spread = (QuantLib::Spread)ValueHelper::Convert (spread); //d
        _CfloatDayCount = safe_cast<CDayCounter^> (floatDayCount);
        _CfloatDayCount->Lock();
        QuantLib::DayCounter& _floatDayCount = static_cast<QuantLib::DayCounter&> (_CfloatDayCount->GetReference ()); 
        _CfloatSchedule = safe_cast<CSchedule^> (floatSchedule);
        _CfloatSchedule->Lock();
        QuantLib::Schedule& _floatSchedule = static_cast<QuantLib::Schedule&> (_CfloatSchedule->GetReference ()); 
        QuantLib::BusinessDayConvention _floatRoll = (QuantLib::BusinessDayConvention)floatRoll ;
        QuantLib::Natural _fixingDays = (QuantLib::Natural)ValueHelper::Convert (fixingDays); //d
        _CfloatIndex = safe_cast<CIborIndex^> (floatIndex);
        _CfloatIndex->Lock();
        boost::shared_ptr<QuantLib::IborIndex>& _floatIndex = static_cast<boost::shared_ptr<QuantLib::IborIndex>&> (_CfloatIndex->GetShared ()); 
        QuantLib::Rate _fixedRate = (QuantLib::Rate)ValueHelper::Convert (fixedRate); //d
        QuantLib::Real _baseCPI = (QuantLib::Real)ValueHelper::Convert (baseCPI); //d
        _CfixedDayCount = safe_cast<CDayCounter^> (fixedDayCount);
        _CfixedDayCount->Lock();
        QuantLib::DayCounter& _fixedDayCount = static_cast<QuantLib::DayCounter&> (_CfixedDayCount->GetReference ()); 
        _CfixedSchedule = safe_cast<CSchedule^> (fixedSchedule);
        _CfixedSchedule->Lock();
        QuantLib::Schedule& _fixedSchedule = static_cast<QuantLib::Schedule&> (_CfixedSchedule->GetReference ()); 
        QuantLib::BusinessDayConvention _fixedRoll = (QuantLib::BusinessDayConvention)fixedRoll ;
        _CobservationLag = safe_cast<CPeriod^> (observationLag);
        _CobservationLag->Lock();
        QuantLib::Period& _observationLag = static_cast<QuantLib::Period&> (_CobservationLag->GetReference ()); 
        _CfixedIndex = safe_cast<CZeroInflationIndex^> (fixedIndex);
        _CfixedIndex->Lock();
        boost::shared_ptr<QuantLib::ZeroInflationIndex>& _fixedIndex = static_cast<boost::shared_ptr<QuantLib::ZeroInflationIndex>&> (_CfixedIndex->GetShared ()); 
        QuantLib::CPI::InterpolationType _observationInterpolation = 
            (Microsoft::FSharp::Core::FSharpOption<QL::Cashflows::CPI::InterpolationTypeEnum>::IsSome::get (observationInterpolation) ? (QuantLib::CPI::InterpolationType)observationInterpolation->Value : QuantLib::CPI::InterpolationType::AsIndex); //10
        QuantLib::Real _inflationNominal = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (inflationNominal) ? (QuantLib::Real)ValueHelper::Convert (inflationNominal->Value) : Null<QuantLib::Real>()); //4
        _ppCPISwap = new boost::shared_ptr<QuantLib::CPISwap> (new QuantLib::CPISwap ( _type,  _nominal,  _subtractInflationNominal,  _spread,  _floatDayCount,  _floatSchedule,  _floatRoll,  _fixingDays,  _floatIndex,  _fixedRate,  _baseCPI,  _fixedDayCount,  _fixedSchedule,  _fixedRoll,  _observationLag,  _fixedIndex,  _observationInterpolation,  _inflationNominal ));
        CPricingEngine^ _CQL_Pricer = safe_cast<CPricingEngine^> (QL_Pricer);
        boost::shared_ptr<QuantLib::PricingEngine>& _QL_Pricer = static_cast<boost::shared_ptr<QuantLib::PricingEngine>&> (_CQL_Pricer->GetShared ());
        (*_ppCPISwap)->setPricingEngine (_QL_Pricer);
        SetSwap (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppCPISwap));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_CfloatDayCount != nullptr) _CfloatDayCount->Unlock();
        if (_CfloatSchedule != nullptr) _CfloatSchedule->Unlock();
        if (_CfloatIndex != nullptr) _CfloatIndex->Unlock();
        if (_CfixedDayCount != nullptr) _CfixedDayCount->Unlock();
        if (_CfixedSchedule != nullptr) _CfixedSchedule->Unlock();
        if (_CobservationLag != nullptr) _CobservationLag->Unlock();
        if (_CfixedIndex != nullptr) _CfixedIndex->Unlock();
    }
}
Cephei::QL::Instruments::CCPISwap::CCPISwap (boost::shared_ptr<QuantLib::CPISwap>& childNative, Object^ owner) : CSwap(CCPISwap::typeid)
{
#ifdef HANDLE
	_phCPISwap = NULL;
#endif
	_ppCPISwap = &childNative;
    _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppCPISwap));
}
Cephei::QL::Instruments::CCPISwap::CCPISwap (QuantLib::CPISwap& childNative, Object^ owner) : CSwap(CCPISwap::typeid)
{
#ifdef HANDLE
	_phCPISwap = NULL;
#endif
	_ppCPISwap = new boost::shared_ptr<QuantLib::CPISwap> (&childNative);
    _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppCPISwap));
    _CPISwapOwner = owner;
    _SwapOwner = owner;
}

Cephei::QL::Instruments::CCPISwap::CCPISwap (CCPISwap^ copy) : CSwap(CCPISwap::typeid)
{
#ifdef HANDLE
	_phCPISwap = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppCPISwap = new boost::shared_ptr<QuantLib::CPISwap> (copy->GetShared());
        _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppCPISwap));
    }
}
Cephei::QL::Instruments::CCPISwap::CCPISwap (PLATFORM::Type^ t) : CSwap(CCPISwap::typeid)
{
#ifdef HANDLE
	_phCPISwap = NULL;
#endif
	if (!t->IsSubclassOf(CCPISwap::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Instruments::CCPISwap::CCPISwap (QuantLib::Handle<QuantLib::CPISwap>& childNative, Object^ owner)  : CSwap(CCPISwap::typeid)
{
	_phCPISwap = &childNative;
	_ppCPISwap = &static_cast<boost::shared_ptr<QuantLib::CPISwap>>(childNative.currentLink());
    _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppCPISwap));
    _CPISwapOwner = owner;
}
Cephei::QL::Instruments::CCPISwap::CCPISwap (QuantLib::Handle<QuantLib::CPISwap> childNative)  : CSwap(CCPISwap::typeid)
{
	_phCPISwap = &childNative;
	_ppCPISwap = &static_cast<boost::shared_ptr<QuantLib::CPISwap>>(childNative.currentLink());
    _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppCPISwap));
}
#endif
#ifdef STRUCT
Cephei::QL::Instruments::CCPISwap::CCPISwap (QuantLib::CPISwap childNative)  : CSwap(CCPISwap::typeid)
{
#ifdef HANDLE
	_phCPISwap = NULL;
#endif
	_ppCPISwap = new boost::shared_ptr<QuantLib::CPISwap> (new QuantLib::CPISwap (childNative));
    _ppSwap = new boost::shared_ptr<QuantLib::Swap> (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppCPISwap));
}
#endif

Cephei::QL::Instruments::CCPISwap::~CCPISwap ()
{
    if (_ppCPISwap != NULL)
    {
	    delete _ppCPISwap;
        _ppCPISwap = NULL;
    }
}
Cephei::QL::Instruments::CCPISwap::!CCPISwap ()
{
    if (_ppCPISwap != NULL)
    {
	    delete _ppCPISwap;
    }
}
QuantLib::CPISwap& Cephei::QL::Instruments::CCPISwap::GetReference ()
{
    if (_ppCPISwap == NULL) throw REFNEW NativeNullException ();
	return **_ppCPISwap;
}
boost::shared_ptr<QuantLib::CPISwap>& Cephei::QL::Instruments::CCPISwap::GetShared ()
{
    if (_ppCPISwap == NULL) throw REFNEW NativeNullException ();
	return *_ppCPISwap;
}
QuantLib::CPISwap* Cephei::QL::Instruments::CCPISwap::GetPointer ()
{
    if (_ppCPISwap == NULL) throw REFNEW NativeNullException ();
	return &**_ppCPISwap;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::CPISwap>& Cephei::QL::Instruments::CCPISwap::GetHandle ()
{
	if (_phCPISwap == NULL)
	{
		_phCPISwap = new Handle<QuantLib::CPISwap> (*_ppCPISwap);
	}
	return *_phCPISwap;
}
#endif
bool Cephei::QL::Instruments::CCPISwap::HasNative () 
{
	return (_ppCPISwap != NULL);
}

Double Cephei::QL::Instruments::CCPISwap::BaseCPI::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCPISwap)->baseCPI ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ Cephei::QL::Instruments::CCPISwap::CpiLeg::get ()
{
    try
    {
    	std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _rv = (std::vector<boost::shared_ptr<QuantLib::CashFlow> >&)(*_ppCPISwap)->cpiLeg ( );   
        CoVector<Cephei::QL::ICashFlow^>^ _nrv = REFNEW CoVector<Cephei::QL::ICashFlow^>(REFNEW CCashFlowVector (_rv, this));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CCPISwap::FairRate::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppCPISwap)->fairRate ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CCPISwap::FairSpread::get ()
{
    try
    {
    	QuantLib::Spread _rv = (QuantLib::Spread)(*_ppCPISwap)->fairSpread ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::IDayCounter^ Cephei::QL::Instruments::CCPISwap::FixedDayCount::get ()
{
    try
    {
    	QuantLib::DayCounter& _rv = (QuantLib::DayCounter&)(*_ppCPISwap)->fixedDayCount ( );   
        Cephei::QL::Times::CDayCounter^ _nrv = REFNEW Cephei::QL::Times::CDayCounter (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Indexes::IZeroInflationIndex^ Cephei::QL::Instruments::CCPISwap::FixedIndex::get ()
{
    try
    {
    	boost::shared_ptr<QuantLib::ZeroInflationIndex>& _rv = (boost::shared_ptr<QuantLib::ZeroInflationIndex>&)(*_ppCPISwap)->fixedIndex ( );   
        Cephei::QL::Indexes::CZeroInflationIndex^ _nrv = REFNEW Cephei::QL::Indexes::CZeroInflationIndex (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CCPISwap::FixedLegNPV::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCPISwap)->fixedLegNPV ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
QL::Times::BusinessDayConventionEnum Cephei::QL::Instruments::CCPISwap::FixedPaymentRoll::get ()
{
    try
    {
    	QuantLib::BusinessDayConvention _rv = (QuantLib::BusinessDayConvention)(*_ppCPISwap)->fixedPaymentRoll ( );   
        QL::Times::BusinessDayConventionEnum _nrv = (QL::Times::BusinessDayConventionEnum)_rv;
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CCPISwap::FixedRate::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppCPISwap)->fixedRate ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::ISchedule^ Cephei::QL::Instruments::CCPISwap::FixedSchedule::get ()
{
    try
    {
    	QuantLib::Schedule& _rv = (QuantLib::Schedule&)(*_ppCPISwap)->fixedSchedule ( );   
        Cephei::QL::Times::CSchedule^ _nrv = REFNEW Cephei::QL::Times::CSchedule (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt32 Cephei::QL::Instruments::CCPISwap::FixingDays::get ()
{
    try
    {
    	QuantLib::Natural _rv = (QuantLib::Natural)(*_ppCPISwap)->fixingDays ( );   
        UInt32 _nrv = (UInt32)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::IDayCounter^ Cephei::QL::Instruments::CCPISwap::FloatDayCount::get ()
{
    try
    {
    	QuantLib::DayCounter& _rv = (QuantLib::DayCounter&)(*_ppCPISwap)->floatDayCount ( );   
        Cephei::QL::Times::CDayCounter^ _nrv = REFNEW Cephei::QL::Times::CDayCounter (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Indexes::IIborIndex^ Cephei::QL::Instruments::CCPISwap::FloatIndex::get ()
{
    try
    {
    	boost::shared_ptr<QuantLib::IborIndex>& _rv = (boost::shared_ptr<QuantLib::IborIndex>&)(*_ppCPISwap)->floatIndex ( );   
        Cephei::QL::Indexes::CIborIndex^ _nrv = REFNEW Cephei::QL::Indexes::CIborIndex (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Cephei::QL::ICashFlow^>^ Cephei::QL::Instruments::CCPISwap::FloatLeg::get ()
{
    try
    {
    	std::vector<boost::shared_ptr<QuantLib::CashFlow> >& _rv = (std::vector<boost::shared_ptr<QuantLib::CashFlow> >&)(*_ppCPISwap)->floatLeg ( );   
        CoVector<Cephei::QL::ICashFlow^>^ _nrv = REFNEW CoVector<Cephei::QL::ICashFlow^>(REFNEW CCashFlowVector (_rv, this));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CCPISwap::FloatLegNPV::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCPISwap)->floatLegNPV ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
QL::Times::BusinessDayConventionEnum Cephei::QL::Instruments::CCPISwap::FloatPaymentRoll::get ()
{
    try
    {
    	QuantLib::BusinessDayConvention _rv = (QuantLib::BusinessDayConvention)(*_ppCPISwap)->floatPaymentRoll ( );   
        QL::Times::BusinessDayConventionEnum _nrv = (QL::Times::BusinessDayConventionEnum)_rv;
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::ISchedule^ Cephei::QL::Instruments::CCPISwap::FloatSchedule::get ()
{
    try
    {
    	QuantLib::Schedule& _rv = (QuantLib::Schedule&)(*_ppCPISwap)->floatSchedule ( );   
        Cephei::QL::Times::CSchedule^ _nrv = REFNEW Cephei::QL::Times::CSchedule (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CCPISwap::InflationNominal::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCPISwap)->inflationNominal ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CCPISwap::Nominal::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCPISwap)->nominal ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
QL::Cashflows::CPI::InterpolationTypeEnum Cephei::QL::Instruments::CCPISwap::ObservationInterpolation::get ()
{
    try
    {
    	QuantLib::CPI::InterpolationType _rv = (QuantLib::CPI::InterpolationType)(*_ppCPISwap)->observationInterpolation ( );   
        QL::Cashflows::CPI::InterpolationTypeEnum _nrv = (QL::Cashflows::CPI::InterpolationTypeEnum)_rv;
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::IPeriod^ Cephei::QL::Instruments::CCPISwap::ObservationLag::get ()
{
    try
    {
    	QuantLib::Period _rv = (QuantLib::Period)(*_ppCPISwap)->observationLag ( );   
        Cephei::QL::Times::CPeriod^ _nrv = REFNEW Cephei::QL::Times::CPeriod (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CCPISwap::Spread::get ()
{
    try
    {
    	QuantLib::Spread _rv = (QuantLib::Spread)(*_ppCPISwap)->spread ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Instruments::CCPISwap::SubtractInflationNominal::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppCPISwap)->subtractInflationNominal ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
QL::Instruments::CPISwap::TypeEnum Cephei::QL::Instruments::CCPISwap::Type::get ()
{
    try
    {
    	QuantLib::CPISwap::Type _rv = (QuantLib::CPISwap::Type)(*_ppCPISwap)->type ( );   
        QL::Instruments::CPISwap::TypeEnum _nrv = (QL::Instruments::CPISwap::TypeEnum)_rv;
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Instruments::ICPISwap^ Cephei::QL::Instruments::CCPISwap_Factory::Create (QL::Instruments::CPISwap::TypeEnum type, Double nominal, Boolean subtractInflationNominal, Double spread, Cephei::QL::Times::IDayCounter^ floatDayCount, Cephei::QL::Times::ISchedule^ floatSchedule, QL::Times::BusinessDayConventionEnum floatRoll, UInt32 fixingDays, Cephei::QL::Indexes::IIborIndex^ floatIndex, Double fixedRate, Double baseCPI, Cephei::QL::Times::IDayCounter^ fixedDayCount, Cephei::QL::Times::ISchedule^ fixedSchedule, QL::Times::BusinessDayConventionEnum fixedRoll, Cephei::QL::Times::IPeriod^ observationLag, Cephei::QL::Indexes::IZeroInflationIndex^ fixedIndex, Microsoft::FSharp::Core::FSharpOption<QL::Cashflows::CPI::InterpolationTypeEnum>^ observationInterpolation, Microsoft::FSharp::Core::FSharpOption<Double>^ inflationNominal, Cephei::QL::IPricingEngine^ QL_Pricer)
{
    return REFNEW CCPISwap ( type,  nominal,  subtractInflationNominal,  spread,  floatDayCount,  floatSchedule,  floatRoll,  fixingDays,  floatIndex,  fixedRate,  baseCPI,  fixedDayCount,  fixedSchedule,  fixedRoll,  observationLag,  fixedIndex,  observationInterpolation,  inflationNominal,  QL_Pricer);
}
